﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace DaveSexton.Labs
{
	/// <summary>
	/// Converts <see cref="OutOfBrowserReason"/> to <see cref="Visibility"/>.
	/// </summary>
	public sealed class OutOfBrowserReasonToVisibilityConverter : IValueConverter
	{
		#region Public Properties
		/// <summary>
		/// Gets or sets the <see cref="OutOfBrowserReason"/> value that converts to <see cref="Visibility.Visible"/>.
		/// </summary>
		/// <value>The default value is <see cref="OutOfBrowserReason.ElevatedTrust"/>.</value>
		public OutOfBrowserReason VisibleValue
		{
			get;
			set;
		}
		#endregion

		#region Private / Protected
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="OutOfBrowserReasonToVisibilityConverter" /> class.
		/// </summary>
		public OutOfBrowserReasonToVisibilityConverter()
		{
			VisibleValue = OutOfBrowserReason.ElevatedTrust;
		}
		#endregion

		#region Methods
		/// <inheritdoc />
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var reason = value is OutOfBrowserReason
				? (OutOfBrowserReason)value
				: VisibleValue;

			return reason == VisibleValue ? Visibility.Visible : Visibility.Collapsed;
		}

		/// <inheritdoc />
		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotSupportedException();
		}
		#endregion
	}
}